#!/usr/bin/env python
from antpy import *

@state
def search(x):
    Sense('Ahead', next, choose_3_ways(search,x), 'Food')
    Move(next, search(x))
    PickUp(go_home((x+1)%3), search(x))

@state
def choose_3_ways(cnt,x):
    Flip(3, next, choose_2_ways(cnt,x))
    Turn('Left', cnt(x))

@state
def choose_2_ways(cnt,x):
    Flip(2, next, forward(cnt,x))
    Turn('Right', cnt(x))

@state
def forward(cnt,x):
    Mark(x, next)
    Move(cnt((x+1)%3), choose_3_ways(cnt,x))
    
@state
def go_home(x):
    Sense('Ahead', next, choose_3_ways(go_home,x), 'Home')
    Move(next, go_home(x))
    Drop(search(x))


if __name__ == '__main__':
    search(0)
    go_home(0)
    for line in Program.output():
        print line

